//
//  TransactionDetailsTableViewController.m
//  Consume100
//
//  Created by eliot on 16/3/28.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "TransactionDetailsTableViewController.h"
#import "TransactionDetailsTableViewCell.h"
#import "PayDetailTableViewController.h"
@interface TransactionDetailsTableViewController ()

@end

@implementation TransactionDetailsTableViewController

+(TransactionDetailsTableViewController*)CreatTransactionDetailsTableViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    TransactionDetailsTableViewController *TransactionDetailsTableViewController=[story instantiateViewControllerWithIdentifier:@"TransactionDetailsTableViewController"];
    
    return TransactionDetailsTableViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerNib:[UINib nibWithNibName:@"TransactionDetailsTableViewCell" bundle:nil] forCellReuseIdentifier:@"TransactionDetailsTableViewCell"];
    self.tableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
    self.title =  @"交易详情";
    /** 设置导航啦样式*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 5;
    }else if (section == 1){
        return 3;
    }else {
        return 1;
    }
   
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        }
        
        if (indexPath.row == 0) {
            cell.textLabel.text = @"配送信息";
        }else if (indexPath.row == 1){
            cell.textLabel.text = @"姓名";
            cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
            cell.detailTextLabel.text = @"杨阿斯";
            cell.detailTextLabel.textColor = [UIColor blackColor];
        }else if (indexPath.row == 2){
            cell.textLabel.text = @"联系电话";
            cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
            UITextField *textField = [[UITextField alloc] init];
            [cell addSubview:textField];
            [textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-8);
                make.top.mas_equalTo(4);
                make.bottom.mas_equalTo(-4);
                make.width.mas_equalTo(Width / 2.0 + 40);
            }];
            textField.font = [UIFont systemFontOfSize: 16];
            textField.textAlignment = NSTextAlignmentRight;
            textField.placeholder = @"请输入联系电话";
        }else if (indexPath.row == 3){
            cell.textLabel.text = @"城市地址";
            cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
            UITextField *textField = [[UITextField alloc] init];
            [cell addSubview:textField];
            [textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-18);
                make.top.mas_equalTo(4);
                make.bottom.mas_equalTo(-4);
                make.width.mas_equalTo(Width / 2.0 + 40);
            }];
            textField.font = [UIFont systemFontOfSize: 16];
            textField.textAlignment = NSTextAlignmentRight;
            textField.placeholder = @"选择市区";
            UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
            [cell addSubview:iv];
            [iv mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(17.5);
                make.right.mas_equalTo(0);
                make.size.mas_equalTo(CGSizeMake(18, 15));
            }];
            iv.contentMode = UIViewContentModeScaleAspectFit;
          
        }else if (indexPath.row == 4){
            cell.textLabel.text = @"详细地址";
            cell.textLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1];
            UITextField *textField = [[UITextField alloc] init];
            [cell addSubview:textField];
            [textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-8);
                make.top.mas_equalTo(4);
                make.bottom.mas_equalTo(-4);
                make.width.mas_equalTo(Width / 2.0 + 40);
            }];
            textField.font = [UIFont systemFontOfSize: 16];
            textField.textAlignment = NSTextAlignmentRight;
            textField.placeholder = @"请输入详细地址";
        }
        return cell;
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0){
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if (!cell) {
                cell = [[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
            }
            cell.textLabel.text = @"已选商品";
            return cell;
        }else {
                TransactionDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TransactionDetailsTableViewCell" forIndexPath:indexPath];
                cell.iconIV.layer.cornerRadius = 8;
                cell.iconIV.layer.masksToBounds = YES;
                return cell;
            }
        
    }else if (indexPath.section == 2) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        }
        cell.textLabel.text = @"订单总价";
        cell.detailTextLabel.text = @"￥336.00";
        cell.detailTextLabel.textColor = [UIColor redColor];
        return cell;
    }else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lastCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lastCell"];
        }
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cell addSubview:btn];
        btn.backgroundColor = [UIColor colorWithRed:255/255.0 green:88/255.0 blue:88/255.0 alpha:1];
        [btn setTitle:@"提交订单" forState:UIControlStateNormal];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-20);
            make.top.mas_equalTo(5);
            make.bottom.mas_equalTo(-5);
        }];
        [btn addTarget:self action:@selector(placeOrder) forControlEvents:UIControlEventTouchUpInside];
        btn.layer.cornerRadius = 8;
        btn.layer.masksToBounds = YES;
        cell.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
        return cell;
    }
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 50;
    }else if(indexPath.section == 1) {
        if (indexPath.row == 0) {
            return 50;
        }else {
            return 86;
        }
    }else {
        return 50;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 10;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 3) {
        return 20 ;
    }else {
        return 0;
    }
    
    
}

//
/** 提交订单*/
- (void)placeOrder {
    PayDetailTableViewController *vc = [PayDetailTableViewController CreatTransactionDetailsTableViewController];
    
    [self creatNav:vc];

}

//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


